﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UIShare;

namespace EFong.View.BankAccount
{
    public partial class Frm_OtherPayment : BasicForm
    {

        // PRIVATE : MEMEBERS :::::::::::::::::::::::::::::::::::::: //

        private Proxy.FinanceServiceProxy _financeProxy {get{ return Proxy.FinanceServiceProxy.GetInstance();}}
        private Proxy.MasterServiceProxy _masterProxy { get { return Proxy.MasterServiceProxy.GetInstance(); } }
        
        public Frm_OtherPayment()
        {
            InitializeComponent();
        }

        // PROTECTED : METHODS :::::::::::::::::::::::::::::::::::::: //

        protected override void InitFields()
        {
            base.InitFields();
        }

        protected override void LoadDatas()
        {
            List<Contract.BankAccount> bankAccountList = _masterProxy.GetAllBankAccount().ReturnValue;
            this.cmb_BankAccount.Properties.BindingData(bankAccountList);
        }

        protected override void Events()
        {
            base.Events();
            this.btn_OK.Click += (s, e) => { 
                // TODO : SAVEING DATE TO DATEBAE ...
                UIOperManager.SaveData(
                            () =>
                            {
                                return true;
                            },
                                () =>
                                {
                                    return _financeProxy.Payment( updateToOtherPaymment()).IsSuccess;
                                },
                                MsgResource.Save_Complete,
                                () =>
                                {
                                    DialogResult = DialogResult.OK;
                                    this.Close();
                                }
                            );
            };

            this.btn_Cancel.Click += (s, e) => {
                // TODO : CANCENING FORM..
                this.Close();
            };
        }

        // PRIVATE : METHODS :::::::::::::::::::::::::::::::::::::: //

        private Contract.OtherPayment updateToOtherPaymment() {
            return new Contract.OtherPayment() { 
                ID = Guid.NewGuid(),
                Amount = txt_Amount.GetValue(),
                BankAccount = (Contract.BankAccount)cmb_BankAccount.GetValue(),
                Date = dte_Date.GetValue(DateTime.MinValue),
                 Remark = txt_Remark.Text,
                Content = txt_Content.Text,
                Type = ((chk_FixedAmount.Checked) ? chk_FixedAmount.Text : chk_SpreadAmount.Text)
            };
        }



    }
}
